<#include "/template/_openwin.html" /> <#assign title="用户扩展信息配置">
<@buttons>
<a href="#" class="easyui-linkbutton"
	data-options="plain:true,iconCls:'icon-save'" onclick="save()">保存扩展信息</a>
<a href="#" class="easyui-linkbutton"
	data-options="plain:true,iconCls:'icon-edit'" onclick="saveRoleCfg()">保存角色配置</a>
</@buttons> <@body>

<div class="easyui-tabs" fit="true" data-options="tabPosition:'left'">
	<div title="基本扩展信息" style="padding: 10px"></div>
	<div title="部门配置">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'west',split:false" style="width: 220px">
				<ul id="lefttree" class="easyui-tree" url="${root!}/frameuserconfig/deptDutyTree"></ul>
				<div id="mm" class="easyui-menu" style="width: 120px;">
					<div onclick="addDeptMain()" data-options="iconCls:'icon-add'">设为主部门</div>
					<div onclick="addDeptSub()" data-options="iconCls:'icon-remove'">设为兼职部门</div>
				</div>
				<script type="text/javascript">
				
					$(function() {
						$('#lefttree').tree({
							animate : true,
							onContextMenu : function(e, node) {
								e.preventDefault();
								$(this).tree('select', node.target);
								if (node.attributes.isreal == "1" || node.attributes.type == "duty") {
									$('#mm').menu('show', {
										left : e.pageX,
										top : e.pageY
									});
								};
							},
							onBeforeLoad : function(node,param){
								param.type = node ? node.attributes.type :'';
							}
						});
					});

					function addDeptMain() {
						var node = $('#lefttree').tree("getSelected");
						var deptid=node.attributes.deptId;
						var dutyid=node.attributes.dutyId;
						$.ajax({
							url : "${root!}/frameuserconfig/addUserDept?userid=${userId!}&deptid="+deptid+"&ismain=1&dutyid="+dutyid,
							type : "POST",
							success : function(msg) {
								Alert.info(msg,"",function(){
									$('#dgOU').datagrid('reload');
								});
							}
						});
					}
					
					
					function addDeptSub(){
						var node = $('#lefttree').tree("getSelected");
						var deptCode=node.attributes.deptCode;
						var deptid=node.attributes.deptId;
						var dutyid=node.attributes.dutyId;
						$.ajax({
							url : "${root!}/frameuserconfig/addUserDept?userid=${userId!}&deptid="+deptid+"&ismain=0&dutyid="+dutyid,
							type : "POST",
							success : function(msg) {
								Alert.info(msg,"",function(){
									$('#dg-sub').datagrid('reload');
								});
							}
						});
					}
				</script>
			</div>
			<div data-options="region:'center'">
				<div class="easyui-layout" data-options="fit:true">
					<div data-options="region:'north',split:false"
						style="height: 150px">

						<@datatable toolbar="#tb" id="dgOU" model="${root!}/frameuserconfig/myOu?isMain=1&id=${userId!}"
						fit="true" hidePagination="true" onLoadSuccess="tableSuccess"> 
						<@columns> 
							<@column name="deptName" title="部门名称" width="0.4" />
							<@column name="dutyName" title="职务" width="0.4" />
							<@column title='操作' width="0.3" formatter="operate" />
							<@column name="id"  hidden="true" />
							<@column name="deptid"  hidden="true" />
						</@columns>
						</@datatable>

					</div>
					<div data-options="region:'center'">
						<@datatable toolbar="#tb" id="dg-sub" model="${root!}/frameuserconfig/myOu?isMain=0&id=${userId!}"
						fit="true" hidePagination="true" onLoadSuccess="tableSuccess"> 
						<@columns> 
							<@column name="deptName" title="部门名称" width="0.4" />
							<@column name="dutyName" title="职务" width="0.4" />
							<@column title='操作' width="0.3" formatter="operate" />
							<@column name="id"  hidden="true" />
							<@column name="deptid"  hidden="true" />
						</@columns>
						</@datatable>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div title="角色配置" 
		style="padding: 0px">
			<div id="pp" style="position: relative">
			<div style="width: 48%;padding:5px;">
				<#list types as a>
						<#if a_index%2==0 >
							<div title="${a.roleTypeName}" closable="false"
								style="height: auto;">
								<@checkboxgroup id="${a.id}" url="${root!}/frameuserconfig/roles?id=${a.id}&userId=${userId!}" name="checkrole" />
							</div>
						</#if>
				</#list>
			</div>
			<#if (types?size>1) >
				<div style="width: 48%;padding:5px;">
						<#list types as a>
							<#if a_index%2!=0 >
							<div title="${a.roleTypeName}" closable="false"
								style="height: auto;">
								<@checkboxgroup id="${a.id}" url="${root!}/frameuserconfig/roles?id=${a.id}&userId=${userId!}" name="checkrole" />
							</div>
							</#if>
						</#list>
				</div>
			</#if>
				
			</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$('#pp').portal({
		border:false,
		fit:true
	});
});

function saveRoleCfg(){
	var str="";
	var list = document.getElementsByName("checkrole");
	for(var i=0;i<list.length;i++){
		if(list[i].checked){
			str+=list[i].value+",";
		}
	}
	$.ajax({
		url:"${root!}/frameuserconfig/saveUserRole",
		type:"POST",
		data:{
			checkedRoles:str,
			userId:${userId!}
		},
		success:function(msg){
			Alert.info(msg,"系统消息");
		}
	});
}

function operate(val,row){
	return '<a class="deleteBtn" onclick="deleteUDR(\''+row.id+'\');" href="#" >删除</a>';
}

function deleteUDR(_id){
	$.ajax({
		url : "${root!}/frameuserconfig/deleteDept",
		data : {id:_id},
		type : "POST",
		success : function(msg){
			$('#dgOU').datagrid('reload');
			$('#dg-sub').datagrid('reload');
		}
	});
}

function tableSuccess(){
	$('.deleteBtn').each(function(){
		$(this).linkbutton({  
		    iconCls: 'icon-cancel',
		    plain:true
		});
	});
}

</script>
</@body>
